﻿@model FilStartUps_Mobile.Models.LogOnModel
@{
    ViewBag.Title = "Login";
}

<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function () {
        $('#loginform_').validate(
           {
               errorClass: "error_login",
               rules: {
                   emailaddress: "required",
                   password: "required"
               },
               messages: {
                   emailaddress: "*",
                   password: "*"
               },
               submitHandler: function () {
                   submit_login();
               }

           })
    });

       function submit_login() {
           $('#loginstatus').addClass('success').html('<img src="../Content/images/ajax-loader.gif"></img>');
           $('#loginform_').ajaxSubmit(
        function (response) {
            var json = JSON.parse(response);

            if (json == true) {
                window.location.href = "/Home/Index";
            }
            else {
                $('#loginstatus').removeClass('success').html('');
                $('#loginstatus').addClass('error').text('Invalid Username or Password');
            }
        })
       }
</script>

<h2>
    Login</h2>
    <div id="login_status"></div>
@using (Html.BeginForm("ValidateUser", "Home", FormMethod.Post, new { @id = "loginform_" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div class="editor-label">
            @Html.LabelFor(model => model.emailaddress)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.emailaddress)
            @Html.ValidationMessageFor(model => model.emailaddress)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.password)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.password)
            @Html.ValidationMessageFor(model => model.password)
        </div>
        <p>
            <div data-role="controlgroup" data-type="horizontal">
                <input type="submit" data-inline="true" value="Login" />
                <a href="Index" data-role="button" >Cancel</a>
            </div>
        </p>
    </fieldset>
}